using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace DecisionMaking.WebApp.Charts
{
    public class FusionChartsLine2DBuilder<T> : FusionChartBuilder<T>
    {
        private const string CHART_NAME = "FCF_MSLine.swf";

        /// <summary>
        /// The label for the X axis.
        /// </summary>
        private string mXAxisLabel;

        /// <summary>
        /// The label for the Y axis.
        /// </summary>
        private string mYAxisLabel;

        private T _YAxisMinValue;

        private T _YAxisMaxValue;

        public FusionChartsLine2DBuilder(HtmlHelper helper, string baseUrl, int[] categories, IEnumerable<DataSet<T>> data, Func<T, double> valueExtractor, int width, int height)
            : base(helper, baseUrl + CHART_NAME, categories, data, valueExtractor, width, height)
        {

        }

        /// <summary>
        /// Writes the X and Y axis labels.
        /// </summary>
        /// <param name="xml"></param>
        internal override void WriteGraphProperties(StringBuilder xml)
        {
            xml.Append("showvalues='0' ");

            if (mXAxisLabel != null) xml.AppendFormat(" xAxisName='{0}'", mXAxisLabel);

            if (mYAxisLabel != null) xml.AppendFormat(" yAxisName='{0}'", mYAxisLabel);

            if (_YAxisMinValue != null) xml.AppendFormat(" yaxisminvalue='{0}'", _YAxisMinValue);

            if (_YAxisMaxValue != null) xml.AppendFormat(" yaxismaxvalue='{0}'", _YAxisMaxValue);
        }

        /// <summary>
        /// Sets the label for the X Axis.
        /// </summary>
        /// <param name="xAxisLabel"></param>
        /// <returns></returns>
        public FusionChartsLine2DBuilder<T> XAxisLabel(string xAxisLabel)
        {
            mXAxisLabel = xAxisLabel;

            return this;
        }

        /// <summary>
        /// Sets the label for the Y Axis.
        /// </summary>
        /// <param name="yAxisLabel"></param>
        /// <returns></returns>
        public FusionChartsLine2DBuilder<T> YAxisLabel(string yAxisLabel)
        {
            mYAxisLabel = yAxisLabel;

            return this;
        }

        public FusionChartsLine2DBuilder<T> YAxisMinValue(T value)
        {
            _YAxisMinValue = value;

            return this;
        }

        public FusionChartsLine2DBuilder<T> YAxisMaxValue(T value)
        {
            _YAxisMaxValue = value;

            return this;
        }
    }
}